package com.sinochem.yunlian.ship.common.util;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StringUtil {

	private static final Logger log = LoggerFactory.getLogger(StringUtil.class);
	/**
	 * String类型转为集合对象
	 * @param values
	 * @param regex
	 * @return
	 */
	public static List<String> stringToList(String values, String regex) {
		
		log.info("参数values:{};regex:{}", values, regex);
		
		if (!StringUtils.isNoneEmpty(values)) {
			return null;
		}
		
		String[] strs = values.split(regex);
		
		if (strs == null || strs.length == 0) {
			return null;
		}
		List<String> lists = new ArrayList<>();
		for (String str : strs) {
			lists.add(str);
		}
		log.info("返回的集合对象:{}", lists);
		return lists;
	}

	/**
	 * 手机号脱敏
	 * */
	public static String getEncryptedPhone(String mobile) {
		if (StringUtils.isBlank(mobile)) {
			return "";
		}
		String encryptedPhone = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
		return encryptedPhone;
	}

	public static void main(String[] args) {
		System.out.print(getEncryptedPhone("18600672114"));
	}
}
